import urllib.request


def proxy_user():
    proxy_list = [
        {"http": "218.22.102.107:80"},
        {"http": "121.31.192.126:8123"},
        {"http": "171.39.28.209:8123"},
        {"http": "115.46.79.142:8123"},
        {"http": "106.75.9.39:8080"},
        {"http":"115.46.79.142:8000"}
    ]

    for proxy in proxy_list:
        print(proxy)
        proxy_handler = urllib.request.ProxyHandler(proxy)
        opener = urllib.request.build_opener(proxy_handler)

        # 如果回来的 response的状态码 不是200 就代表 这个代理IP不能用

        try:
            response = opener.open("http://www.baidu.com",timeout=1)

            code = response.getcode()
            print(proxy)
        except  Exception as e:
            print(e)




proxy_user()
